<!DOCTYPE HTML>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>第三方设置密码</title>
    <link rel="stylesheet" type="text/css" href="../../css/main.css" />

    <style>
        * {
            background: #e6e6e6;
        }

        .password {
            height: 50px;
            background: #fff;
            padding-left: 42px;
            line-height: 50px;
            border-bottom: 3px solid #e3e3e3;
            margin-top: 12px;
        }

        .in {
            margin-left: 37px;
            background: #fff;
            font-size: 16px;
        }

        .below {
            margin: 92px 27px 0px 27px;
            height: 38px;
            background: #ea5718;
            color: #fff;
            line-height: 38px;
            text-align: center;
            border-radius: 5px;
        }
        .delete {
            position: absolute;
            right: 22px;
            top: 100px;
            width: 10px;
            height: 10px;
        }
    </style>

    <body>
      <div id="vm">
        <div class="big-box">
            <div class="verify">设置密码
                <img src="../../image/login/back.png" class="back" onclick="closeWin()">
            </div>
            <div class="password">
                密码<input type="possword" placeholder="请输入密码" v-model="oldpassword" @focus="jiaodian()" @blur="shijiaodian()" class="in" v-on:input="addinput"/>
                  <img src="../../image/login/delete.png" class="delete" v-if="isshowdelete" @click="qingchu()">
            </div>
            <div class="below" v-on:click="submit()">
                确定
            </div>
        </div>
        </div>
    </body>
    <script type="text/javascript" src="../../script/api.js"></script>
    <script type="text/javascript" src="../../script/config.js"></script>
    <script type="text/javascript" src="../../script/rest.js"></script>
    <script type="text/javascript" src="../../script/vue.2.5.js"></script>
    <script type="text/javascript" src="../../script/zepto.js"></script>
    <script type="text/javascript" src="../../script/faskclick.js"></script>
    <script type="text/javascript" src="../../script/jiguang.js"></script>
    <script type="text/javascript">
    var vm = new Vue({
        el: '#vm',
        data: {
            oldpassword: '',
            isshowdelete: false
        },
        created: function() {
            var _this = this;
            apiready = function() {
                _this.init();
                api.parseTapmode();
                var header = $api.byId('aui-header');
                $api.fixStatusBar(header);
                if ('addEventListener' in document) {
                    document.addEventListener('DOMContentLoaded', function() {
                        FastClick.attach(document.body);
                    }, false);
                }
            }
        },
        methods: {
            init: function() {
              var _this = this;
              _this.oldpassword = '';
            },
            addinput:function(){
              var _this = this;
              _this.oldpassword=_this.oldpassword.replace(/[^\w\/]/ig,'');
              if(_this.oldpassword.length>16){
                api.toast({
                    msg: '密码不能超过16位！',
                    duration: 2000,
                    location: 'middle'
                });
              _this.oldpassword=_this.oldpassword.substr(0,16);
            }
            },
            jiaodian() {
                // 输入框获取焦点
                var _this = this;
                _this.isshowdelete = true
            },
            shijiaodian() {
                // 输入框失去焦点
                var _this = this;
                // api.sendEvent({
                //     name: 'phonea',
                //     extra: {
                //         key1: _this.mobile,
                //
                //     }
                // });

            },
            qingchu: function() {
                var _this = this;
                var systemType = api.systemType;
                if (systemType == 'ios') {
                    _this.oldpassword = '';
                }
                _this.oldpassword = '';
                _this.isshowdelete = false

            },
            submit: function() {
                var _this = this;
                if (!_this.oldpassword) {
                    api.toast({
                        msg: '请输入密码！',
                        duration: 2000,
                        location: 'middle'
                    });
                } else if(_this.oldpassword.length<6||_this.oldpassword.length>16){
                  api.toast({
                      msg: '请输入6-16的密码！',
                      duration: 2000,
                      location: 'middle'
                  });
                }else {
                  var data = {};
                  var third=api.pageParam.third;
                  var thirdopenid=api.pageParam.thirdopenid;
                  if (third == 'wx') {
                      third = 'weixin'
                  }
                  var deviceId = api.deviceId;
                  data['device_id'] = deviceId;
                  data[third] = thirdopenid;
                  data['mobile'] = api.pageParam.mobilevalue;
                  data['password'] = _this.oldpassword;
                  var uname=api.pageParam.uname;
                  if (third == 'weixin') {
                      data['wxname'] = uname
                  }else if(third == 'qq'){
                    data['qqname'] = uname
                  }else if(third == 'weibo'){
                    data['weiboname'] = uname
                  }
                  new rest().get('registerThird').datae(data).success(function(res) {
                    if(res.flag==1){
                      jiguang.bingdalias(res.msg.uid)
                      $api.setStorage('uid', res.msg.uid);
                      $api.setStorage('session', res.msg.session);
                      api.sendEvent({
                          name: 'loginsuccess',
                      });
                      if (res.qqname||res.wxname||res.weiboname) {
                      }else {
                         _this.finishUserInfo({_uid:res.msg.uid,nickname:uname,session:res.msg.session})
                      }

                      setTimeout(function() {
                        api.closeWin({
                            name: 'verifyrepirthird'
                        });
                        api.closeWin();
                      }, 2000);
                    }

                  }).error(function(err) {
                      api.toast({
                          msg: err.msg,
                          duration: 2000,
                          location: 'center'
                      });
                  }).run()


                }
            },
            finishUserInfo:function(data) {
              new rest().get('finishUserInfo').datae(data).success(function(res) {
                  if (res.flag == 1) {
                      api.toast({
                          msg: '设置成功',
                          duration: 2000,
                          location: 'middle'
                      });
                  } else {
                      api.toast({
                          msg: res.msg,
                          duration: 2000,
                          location: 'middle'
                      });
                  }
                  console.log(JSON.stringify(res))
              }).error(function(err) {
                  console.log(JSON.stringify(err))
              }).run()

            },
        }
    })
      //关闭
          function closeWin(){
            api.closeWin();

          }
    </script>
</html>
